#include "CInterestBar.h"

CInterestBar::CInterestBar(void)
{
}

CInterestBar::~CInterestBar(void)
{
}
CInterestBar* CInterestBar::GetInstance()
{
	static CInterestBar instance;
	return &instance;
}

void CInterestBar::Render(CUnit* pUnit)
{
	float fPercent;
	m_rDrawRect.left = (LONG)(pUnit->GetDrawRect().left);
	if(pUnit->CurrInterest() >= pUnit->MaxInterest())
		fPercent = 1;
	else
		fPercent = (((int)pUnit->CurrInterest()%(int)pUnit->MaxInterest())*(100/(float)(pUnit->MaxInterest()))) * 0.01f;
	int nRight = m_rDrawRect.left + 20;
	int length = (int)Lerp(
		(float)m_rDrawRect.left, (float)nRight, fPercent);
	m_rDrawRect.right = (LONG)( length);
	m_rDrawRect.top = (LONG)pUnit->GetDrawRect().top - 5;
	m_rDrawRect.bottom = (LONG)(
		m_rDrawRect.top + 5);

	//////////////////////////////////////////////////////////////
	//	Render
	CSGD_Direct3D::GetInstance()->SpriteEnd();
	//	Interest Bar
	CSGD_Direct3D::GetInstance()->DrawRect(
		m_rDrawRect, 0,0,255);
	//  Interest Bar Outline
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.top, 
		nRight, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.top, 
		nRight, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		nRight, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.bottom, 0,0,0);
	CSGD_Direct3D::GetInstance()->DrawLine(
		m_rDrawRect.left, m_rDrawRect.bottom, 
		m_rDrawRect.left, m_rDrawRect.top, 0,0,0);
	CSGD_Direct3D::GetInstance()->SpriteBegin();
	//
	//////////////////////////////////////////////////////////////
}

//void CInterestBar::Render(CHero* pUnit)
//{
//	float fPercent;
//	m_rDrawRect.left = (LONG)(pUnit->GetDrawRect().left);
//	if(pUnit->GetCurrHP() == pUnit->GetMaxHP())
//		fPercent = 1;
//	else
//		fPercent = ((pUnit->GetCurrHP()%pUnit->GetMaxHP())*(100/(float)(pUnit->GetMaxHP()))) * 0.01f;
//	int nRight = m_rDrawRect.left + 20;
//	int length = (int)Lerp(
//		(float)m_rDrawRect.left, (float)nRight, fPercent);
//	m_rDrawRect.right = (LONG)( length);
//	m_rDrawRect.top = (LONG)pUnit->GetDrawRect().top - 5;
//	m_rDrawRect.bottom = (LONG)(
//		m_rDrawRect.top + 5);
//
//	//////////////////////////////////////////////////////////////
//	//	Render
//	CSGD_Direct3D::GetInstance()->SpriteEnd();
//	//	Interest Bar
//	CSGD_Direct3D::GetInstance()->DrawRect(m_rDrawRect, 255,0,0);
//	//  Interest Bar Outline
//	CSGD_Direct3D::GetInstance()->DrawLine(
//		m_rDrawRect.left, m_rDrawRect.top, 
//		nRight, m_rDrawRect.top, 0,0,0);
//	CSGD_Direct3D::GetInstance()->DrawLine(
//		nRight, m_rDrawRect.top, 
//		nRight, m_rDrawRect.bottom, 0,0,0);
//	CSGD_Direct3D::GetInstance()->DrawLine(
//		nRight, m_rDrawRect.bottom, 
//		m_rDrawRect.left, m_rDrawRect.bottom, 0,0,0);
//	CSGD_Direct3D::GetInstance()->DrawLine(
//		m_rDrawRect.left, m_rDrawRect.bottom, 
//		m_rDrawRect.left, m_rDrawRect.top, 0,0,0);
//	CSGD_Direct3D::GetInstance()->SpriteBegin();
//	//
//	//////////////////////////////////////////////////////////////
//}